package de.tu_darmstadt.gdi1.towerdefense.model.towermodel;

import java.awt.Point;
import java.util.Iterator;
import java.util.Vector;

import de.tu_darmstadt.gdi1.towerdefense.model.mapmodel.AMap;
import de.tu_darmstadt.gdi1.towerdefense.model.monstermodel.Monster;
import de.tu_darmstadt.gdi1.towerdefense.model.playermodel.PlayerModel;

public class SniperTower extends DamageTower {

	private static final double cost = 1000;
	private static int baseDamage = 50;
	private static int radius = 10;
	private static final int cooldown = 5;
	private static final int upgradeCost = 1000;
	private int cooldownUntilNextShot;
	private int level;
	private int damage;

	public SniperTower(Point location) {
		super(cost, radius, location);
		cooldownUntilNextShot = cooldown;
		damage = baseDamage;
		level = 1;
	}

	public void damageMonsters(Vector<Monster> monsters, AMap aMap,
			PlayerModel player) {
		if (cooldownUntilNextShot == 0) {
			for (Iterator<Monster> m = monsters.iterator(); m.hasNext();) {
				Monster monster = m.next();
				if (monster.getLivePoints() > 0) {
					if (monster.getPositon().distance(getLocation()) <= getTowerRadius())
						monster.setLivePoints(monster.getLivePoints() - damage);
					if (monster.getLivePoints() <= 0) {
						aMap.removeMonsterFromMap(monster.getPositon().x,
								monster.getPositon().y);
						monsters.remove(monster);
						player.addCredits(monster.getCreditsOfMonster());
					}
					cooldownUntilNextShot = cooldown;
					return;
				}
			}
		} else
			cooldownUntilNextShot--;
	}

	public boolean upgradeTower() {
		if (super.getMaxTowerLevel() > level) {
			level++;
			damage = damage + baseDamage * level;
			return true;
		}
		return false;
	}

	public double getUpgradeCost() {
		return upgradeCost * level;
	}

}
